using System;
using System.Globalization;

namespace WLCompiler.Helpers.Extensions
{
    internal static class EnumExtensions
    {
        public static string GetParamString(this Enum @enum)
        {
            var type = @enum.GetType();
#pragma warning disable 612,618
            var fieldInfo = type.GetField(@enum.ToString(CultureInfo.InvariantCulture));
#pragma warning restore 612,618

            var attributes = fieldInfo.GetCustomAttributes(typeof(StringContentAttribute), false) as StringContentAttribute[];

            if (attributes != null && attributes.Length > 0)
            {
                return attributes[0].Content;
            }
            
#pragma warning disable 612,618
            return @enum.ToString(CultureInfo.InvariantCulture);
#pragma warning restore 612,618
        }
    }
}